<?php

use think\migration\Migrator;
use Phinx\Db\Adapter\MysqlAdapter;

class StoreUserLevelTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {   
        $table = $this->table('store_user_level');
        $table->addColumn('store_puser_id','integer',array('limit' => MysqlAdapter::INT_REGULAR,'comment' => '父级用户id'))->addIndex('store_puser_id');
        $table->addColumn('store_user_id','integer',array('limit' => MysqlAdapter::INT_REGULAR,'comment' => '用户id'))->addIndex('store_user_id');
        $table->addColumn('level','boolean',array('limit' => 1,'comment' => '所附父级用户层级'));
        $table->create();
        $this->up();
    }


    public function up()
    {
        $rows = [
            [
              'store_puser_id'    => 2,
              'store_user_id'  => 1,
              'level' => 1,
            ]
        ];

        $this->table('store_user_level')->insert($rows)->save();
    }
}
